package cn.wolfcode.cms.service.impl;

import cn.wolfcode.cms.domain.ExpenditureItems;
import cn.wolfcode.cms.mapper.ExpenditureItemsMapper;
import cn.wolfcode.cms.query.QueryObject;
import cn.wolfcode.cms.service.IExpenditureItemsService;
import cn.wolfcode.cms.util.PageResult;
import cn.wolfcode.cms.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ExpenditureItemsServiceImpl implements IExpenditureItemsService {

    @Autowired
    private ExpenditureItemsMapper expenditureItemsMapper;

    public void save(ExpenditureItems entity) {
        entity.setTime(new Date());
        entity.setEmployee(UserContext.getCurrentUser());
        expenditureItemsMapper.insert(entity);

    }

    public void update(ExpenditureItems entity) {
        expenditureItemsMapper.updateByPrimaryKey(entity);
    }

    public void delete(Long id) {
        expenditureItemsMapper.deleteByPrimaryKey(id);
    }

    public ExpenditureItems get(Long id) {
        return expenditureItemsMapper.selectByPrimaryKey(id);
    }

    public List<ExpenditureItems> list() {
        return expenditureItemsMapper.selectAll();
    }

    public Object query(QueryObject qo) {
        //查总数
        int total = expenditureItemsMapper.queryForCount(qo);
        if (total == 0) {
            return new PageResult();
        }
        //查数据
        List<ExpenditureItems> rows = expenditureItemsMapper.queryForList(qo);
        return new PageResult(total, rows);
    }

    @Override
    public Object getTotalAmount() {
        return expenditureItemsMapper.getTotalAmount();
    }

    @Override
    public Object getAnalysis() {
        return expenditureItemsMapper.getAnalysis();
    }

}
